package com.hopes.bizz.risk.hid.bo;

import com.hopes.bizz.common.core.util.DateUtils;
import com.hopes.bizz.common.core.util.StringUtils;

import java.util.Date;
import java.util.Objects;

/**
 * @author yumr
 * @Description 生成检查任务编号
 * @time 2023/8/17 15:34
 */
public class HidTaskNumberProducerBO {

    private static final String INIT_NO_PREFIX = "JC";
    private static final String INIT_NO_SUFFIX = "1";

    private static final String INIT_NO_SPLIT = "-";

    private String preTaskNo;

    private Integer seq;

    public HidTaskNumberProducerBO() {
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    public HidTaskNumberProducerBO(String preTaskNo) {
        this.preTaskNo = preTaskNo;
    }

    public String getTaskNo() {
        String prefix = getNoPrefix();
        return prefix + getTaskSeq();
    }

    public Integer getTaskSeq() {
        if (Objects.nonNull(seq)) {
            return seq > 0 ? seq : 1;
        }

        if (StringUtils.isEmpty(preTaskNo)) {
            return 1;
        }
        return Integer.parseInt(preTaskNo.substring(preTaskNo.lastIndexOf(INIT_NO_SPLIT) + 1)) + 1;
    }


    private String getNoPrefix() {
        return INIT_NO_PREFIX + DateUtils.formatDate(new Date(), "yyyyMMdd") + INIT_NO_SPLIT;
    }

}
